package com.ustc.py.learn.controller;


import com.ustc.py.learn.constant.KnowledgeTypeEnum;
import com.ustc.py.learn.entity.Knowledge;
import com.ustc.py.learn.entity.KnowledgeVo;
import com.ustc.py.learn.service.KnowledgeService;
import com.ustc.py.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 处理学习知识的controller
 */
@Controller
@ResponseBody
@RequestMapping("/learn")
public class LearnController {

    @Autowired
    private KnowledgeService knowledgeService;

    /**
     * 根据id查询knowledge详情
     * @param
     * @return
     */
    @GetMapping("/{id}")
    public R getBasic(@PathVariable("id") int id) {
        Knowledge knowledge = knowledgeService.getKnowledgeById(id);
        return R.jsonify(200, "0K", knowledge);
    }

    /**
     * 查询基础知识的列表
     * vue挂载
     * @return
     */
    @GetMapping("/list")
    public R getAlgorithmKnowledgeList() {
        List<KnowledgeVo> algorithmKnowledgeMenu =
                knowledgeService.getKnowledgeMenuList(KnowledgeTypeEnum.BASIC.getTypeId());
        return R.ok().put("data", algorithmKnowledgeMenu);
    }

    /**
     *
     * @param typeId
     * @param chapterId
     * @return
     */
    @GetMapping("/{typeId}/{chapterId}")
    public R getChapter(@PathVariable("typeId")Integer typeId,@PathVariable("chapterId")Integer chapterId) {
        List<KnowledgeVo> chapterList =
                knowledgeService.getChapter(typeId,chapterId);
        return R.ok().put("data", chapterList);
    }


    /**
     * 测试
     *     GET /learn/{typeId}/{chapterId}/test
     * e.g.,
     *    1) GET /learn/0/3/test 表示测试路径类型0（基础Python语法）的第3章
     * @param typeId
     * @param chapterId
     * @return
     */
/*    @GetMapping("/{typeId}/{chapterId}/test")
    public R test(@PathVariable("typeId") int typeId, @PathVariable("chapterId") int chapterId) {
        Map<String, Integer> data = new HashMap<>();
        data.put("typeId", typeId);
        data.put("chapterId", chapterId);
        return R.jsonify(200, "OK", data);
    }*/
}
